package com.lmoumou.lib_comment.wedgit

import android.content.Context
import android.util.AttributeSet
import android.view.Gravity
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import android.widget.ImageView
import android.widget.LinearLayout
import com.maixun.lib_base.utils.DensityUtil
import com.maixun.lib_comment.R

/**
 * @author:Lmoumou
 * @date:2020/9/12
 * 描述:
 **/
class SearchView : LinearLayout {
    constructor(context: Context) : this(context, null)
    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        orientation = HORIZONTAL
        setBackgroundResource(R.drawable.comment_search_bg)
        gravity = Gravity.CENTER_VERTICAL

        val searchView = EditText(context).apply {
            gravity = Gravity.CENTER_VERTICAL
            background = null
            isSingleLine = true
            hint = "输入医院名称"
            textSize = 14F
            setPadding(
                DensityUtil.dp2px(16F),
                DensityUtil.dp2px(7F),
                DensityUtil.dp2px(16F),
                DensityUtil.dp2px(7F)
            )
            imeOptions = EditorInfo.IME_ACTION_SEARCH
            layoutParams = LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)
        }

        addView(searchView)

        val deleteImageView = ImageView(context).apply {
            layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)
            setImageResource(R.mipmap.comment_search_delete)
            setPadding(DensityUtil.dp2px(16F), 0, DensityUtil.dp2px(16F), 0)
        }


        addView(deleteImageView)
    }
}